package cn.yuanqiao.activiti.service.impl;

import cn.yuanqiao.activiti.domain.ActArchiveData;
import cn.yuanqiao.activiti.mapper.ActArchiveDataMapper;
import cn.yuanqiao.activiti.service.IActArchiveDataService;
import cn.yuanqiao.activiti.util.PdfUtil;

import cn.yuanqiao.archive.sealmanage.service.ISealmanageService;
import cn.yuanqiao.archive.xiaoxitongzhi.service.IYqXxtzService;
import cn.yuanqiao.common.enums.BusinessBehavior;
import cn.yuanqiao.common.util.BusinessBehaviorUtil;
import cn.yuanqiao.common.utils.DateUtils;
import cn.yuanqiao.common.utils.SecurityUtils;

import cn.yuanqiao.common.utils.StringUtils;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.itextpdf.text.DocumentException;
import com.lowagie.text.pdf.PdfReader;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import javax.imageio.stream.FileImageInputStream;
import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 流程档案数据绑定Service业务层处理
 *
 * @author lyk
 * @date 2023-07-11
 */
@Service
public class ActArchiveDataServiceImpl implements IActArchiveDataService
{
    @Autowired
    private ActArchiveDataMapper actArchiveDataMapper;

    @Autowired
    private ISealmanageService SealmanageService;

    @Autowired
    private IYqXxtzService yqXxtzService;

    /**
     * 查询流程档案数据绑定
     *
     * @param deployId 流程档案数据绑定主键
     * @return 流程档案数据绑定
     */
    @Override
    public ActArchiveData selectActArchiveDataByDeployId(String deployId)
    {
        return actArchiveDataMapper.selectActArchiveDataByDeployId(deployId);
    }

    @Override
    public ActArchiveData selectActArchiveDataByArchiveId(String archiveId)
    {
        return actArchiveDataMapper.selectActArchiveDataByArchiveId(archiveId);
    }

    /**
     * 查询流程档案数据绑定列表
     *
     * @param actArchiveData 流程档案数据绑定
     * @return 流程档案数据绑定
     */
    @Override
    public List<ActArchiveData> selectActArchiveDataList(ActArchiveData actArchiveData)
    {
        return actArchiveDataMapper.selectActArchiveDataList(actArchiveData);
    }

    /**
     * 新增流程档案数据绑定
     *
     * @param actArchiveData 流程档案数据绑定
     * @return 结果
     */
    @Override
    public int insertActArchiveData(ActArchiveData actArchiveData)
    {
        actArchiveData.setCreateTime(DateUtils.getNowDate());
        return actArchiveDataMapper.insertActArchiveData(actArchiveData);
    }

    @Override
    public int batchInsertActArchiveData(List<ActArchiveData> actArchiveData)
    {
        /*actArchiveData.setCreateTime(DateUtils.getNowDate());*/
        return actArchiveDataMapper.batchInsertActArchiveData(actArchiveData);
    }

    /**
     * 修改流程档案数据绑定
     *
     * @param actArchiveData 流程档案数据绑定
     * @return 结果
     */
    @Override
    public int updateActArchiveData(ActArchiveData actArchiveData)
    {
        return actArchiveDataMapper.updateActArchiveData(actArchiveData);
    }

    /**
     * 批量删除流程档案数据绑定
     *
     * @param deployIds 需要删除的流程档案数据绑定主键
     * @return 结果
     */
    @Override
    public int deleteActArchiveDataByDeployIds(String[] deployIds)
    {
        return actArchiveDataMapper.deleteActArchiveDataByDeployIds(deployIds);
    }

    /**
     * 删除流程档案数据绑定信息
     *
     * @param deployId 流程档案数据绑定主键
     * @return 结果
     */
    @Override
    public int deleteActArchiveDataByDeployId(String deployId)
    {
        return actArchiveDataMapper.deleteActArchiveDataByDeployId(deployId);
    }

    @Override
    public int updateActArchiveDataEndByDeployId(String processInstanceId) {
        return actArchiveDataMapper.updateActArchiveDataByDeployId(processInstanceId);
    }

    @Override
    public void batchUpdateArchiveState(List<Map<String, Object>> archiveData, String state) {
        //return actArchiveDataMapper.updateActArchiveDataByDeployId(processInstanceId);
        String tenantCode = SecurityUtils.getTenantCode().toUpperCase();
        System.out.println(tenantCode);
        StringBuilder sqlBulider = new StringBuilder();
        List<Map<String,Object>> sqlList = new ArrayList<>();
        for (Map<String, Object> archive:archiveData){
            String archiveAgreeStatus = String.valueOf(archive.get("archiveAgreeStatus"));
            String stateRewrite = state;
            if ("0".equals(archiveAgreeStatus)){
                //单行数据不同意
                stateRewrite = "2";
            }
            String daType = String.valueOf(archive.get("DA_TYPE"));
            String daId = String.valueOf(archive.get("ID"));
            String subTableName = String.valueOf(archive.get("SUB_TABLE_NAME"));
            String categoryId = String.valueOf(archive.get("CATEGORY_ID"));
            String mainTableName = "F".equals(daType.toUpperCase())?"YQDA":"V".equals(daType.toUpperCase())?"YQFOLDER":"X".equals(daType.toUpperCase())?"YQITEM":"";
            String mainTableId = "F".equals(daType.toUpperCase())?"DA_ID":"V".equals(daType.toUpperCase())?"FOLDER_ID":"X".equals(daType.toUpperCase())?"ITEM_ID":"";
            Map<String,Object> map = new HashMap<>();
            map.put("mainTableName",tenantCode+"_"+mainTableName);
            map.put("mainTableId",mainTableId);
            map.put("subTableName",subTableName);
            map.put("state",stateRewrite);
            map.put("daId",daId);
            map.put("tenantCode",tenantCode);
            map.put("daType",daType);
            if ("V".equals(daType)){
                String innerFileTableName = actArchiveDataMapper.getInnerFileTableName(categoryId,tenantCode);
                map.put("innerFileTableName",innerFileTableName);
            }
            if ("X".equals(daType)){
                String innerFolderTableName = actArchiveDataMapper.getInnerFolderTableName(categoryId,tenantCode);
                map.put("innerFolderTableName",innerFolderTableName);
                String innerFileTableName = actArchiveDataMapper.getInnerFileTableName(categoryId,tenantCode);
                map.put("innerFileTableName",innerFileTableName);
            }
            sqlList.add(map);
        }
        actArchiveDataMapper.batchUpdateArchiveState(sqlList);
        //添加过程信息
        if(sqlList.size()!=0){
            addBehavior(sqlList,tenantCode,"daId","daType", BusinessBehavior.GUIDANG);
        }
    }

    @Async
    public void addBehavior(List<Map<String,Object>> sqlList,String tenantCode,String idField,String daTypeField,BusinessBehavior behavior){
        if(sqlList.size()!=0){
            sqlList.stream().forEach(map -> {
                Long daId = Long.valueOf(map.get(idField).toString());
                BusinessBehaviorUtil.add(daId,behavior);
                if("X".equals(String.valueOf(map.get(daTypeField))) || "3".equals(String.valueOf(map.get(daTypeField)))){
                    List<Map<String, Object>> maps = actArchiveDataMapper.executeSql("select folder_id from " + tenantCode + "_ITEM_FOLDER WHERE ITEM_ID = " + daId);
                    maps.stream().forEach(map1 -> {
                        Long folder_id = Long.valueOf(map1.get("FOLDER_ID").toString());
                        BusinessBehaviorUtil.add(folder_id,behavior);
                    });
                    List<Map<String, Object>> maps2 = actArchiveDataMapper.executeSql("select da_id from " + tenantCode + "_YQDA_FOLDER WHERE FOLDER_ID IN (SELECT FOLDER_ID FROM "+tenantCode+"_ITEM_FOLDER where item_id = "+daId+")");
                    maps2.stream().forEach(map2 -> {
                        Long da_id = Long.valueOf(map2.get("DA_ID").toString());
                        BusinessBehaviorUtil.add(da_id,behavior);
                    });
                }
                if("V".equals(String.valueOf(map.get(daTypeField))) || "1".equals(String.valueOf(map.get(daTypeField)))){
                    List<Map<String, Object>> maps = actArchiveDataMapper.executeSql("select da_id from " + tenantCode + "_YQDA_FOLDER WHERE FOLDER_ID = " + daId);
                    maps.stream().forEach(map1 -> {
                        Long da_id = Long.valueOf(map1.get("DA_ID").toString());
                        BusinessBehaviorUtil.add(da_id,behavior);
                    });
                }
            });
        }

    }

    @Override
    public void batchUpdateBorrowDownload(Map<String, Object> borrowData) {
        String sql = "UPDATE yqdaborrow_item set DOWNLOADABLE ='"+(borrowData.get("allowDownload")==null?"0":borrowData.get("allowDownload"))
                +"',DOWNLOAD_COUNT ='"+(borrowData.get("downloadNum")==null?"0":borrowData.get("downloadNum"))+"' where BORROW_ID = "+borrowData.get("borrowId");
        actArchiveDataMapper.executeSql(sql);
    }

    @Override
    public void batchUpdateArchiveBorrowState(Map<String, Object> borrowData,String tenantCode, String state, List<Map<String, Object>> archiveIdsAgree) {
        for (Map<String, Object> archive : archiveIdsAgree) {
            String daType = String.valueOf(archive.get("DA_TYPE"));
            String subTableName = String.valueOf(archive.get("SUB_TABLE_NAME"));
            String id = String.valueOf(archive.get("ID"));
            String tableName = daType.equals("f")?tenantCode+"_YQDA":daType.equals("v")?tenantCode+"_YQFOLDER":tenantCode+"_YQITEM";
            String idName = daType.equals("f")?"DA_ID":daType.equals("v")?"FOLDER_ID":"ITEM_ID";
            String subSql = "UPDATE " + subTableName + " SET STJSFJC ='"+state+"' WHERE ID ='" +id+"';";
            String allSql = "UPDATE " + tableName + " SET STJSFJC ='"+state+"' WHERE "+idName+" ='" +id+"';";
            String unitSql = "";
            if ("v".equals(daType)){
                String categoryId = String.valueOf(archive.get("CATEGORY_ID"));
                String innerFileTableName = actArchiveDataMapper.getInnerFileTableName(categoryId, tenantCode);
                unitSql = "UPDATE " + innerFileTableName + " SET STJSFJC ='"+state+"' WHERE ID IN (SELECT DA_ID FROM "+tenantCode.toUpperCase()+"_YQDA_FOLDER WHERE FOLDER_ID ='" +id+"');"+
                        "UPDATE " + tenantCode.toUpperCase() + "_YQDA SET STJSFJC ='"+state+"' WHERE DA_ID IN (SELECT DA_ID FROM "+tenantCode.toUpperCase()+"_YQDA_FOLDER WHERE FOLDER_ID ='" +id+"');";
            }else if ("x".equals(daType)){
                String categoryId = String.valueOf(archive.get("CATEGORY_ID"));
                String innerFileTableName = actArchiveDataMapper.getInnerFileTableName(categoryId, tenantCode);
                String innerFolderTableName = actArchiveDataMapper.getInnerFolderTableName(categoryId, tenantCode);
                unitSql = "UPDATE " + innerFolderTableName + " SET STJSFJC ='"+state+"' WHERE ID IN (SELECT FOLDER_ID FROM "+tenantCode.toUpperCase()+"_ITEM_FOLDER WHERE ITEM_ID ='" +id+"');"+
                        "UPDATE " + tenantCode.toUpperCase() + "_YQFOLDER SET STJSFJC ='"+state+"' WHERE FOLDER_ID IN (SELECT FOLDER_ID FROM "+tenantCode.toUpperCase()+"_ITEM_FOLDER WHERE ITEM_ID ='" +id+"');"+
                        "UPDATE " + innerFileTableName + " SET STJSFJC ='"+state+"' WHERE ID IN (SELECT DA_ID FROM "+tenantCode.toUpperCase()+"_YQDA_FOLDER WHERE FOLDER_ID IN (SELECT FOLDER_ID FROM "+tenantCode.toUpperCase()+"_ITEM_FOLDER WHERE ITEM_ID ='" +id+"'));"+
                        "UPDATE " + tenantCode.toUpperCase() + "_YQDA SET STJSFJC ='"+state+"' WHERE DA_ID IN (SELECT DA_ID FROM "+tenantCode.toUpperCase()+"_YQDA_FOLDER WHERE FOLDER_ID IN (SELECT FOLDER_ID FROM "+tenantCode.toUpperCase()+"_ITEM_FOLDER WHERE ITEM_ID ='" +id+"'));";
            }
            actArchiveDataMapper.executeSql(subSql+allSql+unitSql);
            //消息通知预约人
            List<Map<String, Object>> maps = actArchiveDataMapper.executeSql("select ID,USER_ID from " + tenantCode + "_APPOINTMENT_FORM where STATUS = 0 and " +
                    " FIND_IN_SET( '" + id + "', DA_IDS::text)>0 ");
            if (maps != null && maps.size() > 0) {
                String userId =String.valueOf(maps.get(0).get("USER_ID"));
                yqXxtzService.addyqXxtzApi("您有" + maps.size() + "条预约的档案已经归还,请于次日12点之前发起借阅!", Long.valueOf(userId),  Long.valueOf(userId), tenantCode);
                String ids =maps.stream().map(m->String.valueOf(m.get("ID"))).collect(Collectors.joining("','"));
                actArchiveDataMapper.executeSql("update " + SecurityUtils.getTenantCode()
                        + "_APPOINTMENT_FORM set borrow_time = "+DateUtils.getTime()+" where  id in ('"+ids+"')");
            }
        }
    }

    @Override
    public void addSeal(List<Map<String, Object>> archiveData) {
        String tenantCode = SecurityUtils.getTenantCode();
        boolean isAdd = true;
        String categoryId = "";
        String daType = "";
        List<Map<String, Object>> maps1 = actArchiveDataMapper.executeSql("select config_value " +
                " from sys_config where config_key = 'SEAL_POSITION' AND TENANTCODE = '" + tenantCode + "'");

        String config_value = "";
        if(null==maps1 || maps1.size()==0 || maps1.get(0)==null){
            System.out.println("归档章路径未配置");
            isAdd = false;
        }else{
            config_value = String.valueOf(maps1.get(0).get("CONFIG_VALUE"));
            if(StringUtils.isEmpty(config_value) || "null".equals(config_value)){
                System.out.println("归档章路径未配置");
                isAdd = false;
            }else{
                File file = new File(config_value + File.separator + tenantCode);
                if(!file.exists()){
                    file.mkdirs();
                }
            }
        }

        Map<String, Object> styleMap = new HashMap<>();
        if(archiveData.size()!=0){
            Map<String, Object> map = archiveData.get(0);
            categoryId = String.valueOf(map.get("CATEGORY_ID"));
            daType = String.valueOf(map.get("DA_TYPE"));
            List<Map<String, Object>> list = actArchiveDataMapper.executeSql("select id,state,category_id,image_path,x_position,y_position,total_height,total_width,TABLE_STYLE,total_height_px,total_width_px from " + tenantCode + "_SEALMANAGE" +
                    " WHERE (CATEGORY_ID = "+categoryId+" or CATEGORY_ID is null) and state = 1");
            if(list==null || list.size()==0){
                isAdd = false;
            }else{
                if(list.size()==1){
                    styleMap = list.get(0);
                }
                if(list.size()>1){
                    for(int i=0;i<list.size();i++){
                        Map<String, Object> map1 = list.get(i);
                        String cateId = String.valueOf(map1.get("CATEGORY_ID"));
                        if(cateId.equals(categoryId)){
                            styleMap = map1;
                            break;
                        }
                    }
                }
            }
        }
        if(isAdd){
            List<Map<String, Object>> maps = actArchiveDataMapper.executeSql("select efile_table_name,file_table_name from " + tenantCode + "_category where id = " + categoryId + "");
            String tableName = String.valueOf(maps.get(0).get("EFILE_TABLE_NAME"));
            String fileTableName = String.valueOf(maps.get(0).get("FILE_TABLE_NAME"));
            String x_position = String.valueOf(styleMap.get("X_POSITION"));
            String y_position = String.valueOf(styleMap.get("Y_POSITION"));
            String total_height = String.valueOf(styleMap.get("TOTAL_HEIGHT"));
            total_height = String.valueOf(styleMap.get("TOTAL_HEIGHT_PX"));
            String total_width = String.valueOf(styleMap.get("TOTAL_WIDTH"));
            total_width = String.valueOf(styleMap.get("TOTAL_WIDTH_PX"));
            String image_path = String.valueOf(styleMap.get("IMAGE_PATH"));
            String table_style = String.valueOf(styleMap.get("TABLE_STYLE"));
            String sealManageId = String.valueOf(styleMap.get("ID"));
            JSONArray jsonArray = JSONArray.parseArray(table_style);
            String columnStr = "";
            for(int i = 0;i<jsonArray.size();i++){    //归档章修改20231128
                JSONArray ja = (JSONArray)jsonArray.get(i);
                for(int j=0;j<ja.size();j++){
                    JSONObject jb = (JSONObject)ja.get(j);
                    String type = String.valueOf(jb.get("type"));
                    if("2".equals(type)){  //动态值
                        JSONObject value = (JSONObject) jb.get("value");
                        columnStr += value.get("value") + ",";
                    }
                }
            }
            if(columnStr.endsWith(",")) columnStr = columnStr.substring(0,columnStr.length()-1);
            for (Map<String, Object> archive:archiveData){
                String daId = String.valueOf(archive.get("ID"));
                List<Map<String, Object>> list = new ArrayList<>();
                List<Map<String, Object>> maps2 = new ArrayList<>();
                if("V".equalsIgnoreCase(daType)){
                    list = actArchiveDataMapper.executeSql("select doc_id,path,DOC_MNT,doc_file_type,real_doc_name from " + tableName + " where is_del=0 and " +
                            "con_table_id in (select da_id from " + tenantCode + "_YQDA_FOLDER where folder_id = " + daId + ")");
                }else
                if("X".equalsIgnoreCase(daType)){
                    list = actArchiveDataMapper.executeSql("select doc_id,path,DOC_MNT,doc_file_type,real_doc_name from " + tableName + " where is_del=0 and " +
                            "con_table_id in (select da_id from " + tenantCode + "_YQDA_FOLDER where folder_id in (select folder_id from "+tenantCode+"_ITEM_FOLDER WHERE ITEM_ID = "+daId+"))");
                }else{
                    list = actArchiveDataMapper.executeSql("select doc_id,path,DOC_MNT,doc_file_type,real_doc_name from " + tableName + " where is_del=0 and " +
                            "con_table_id = " + daId + "");
                }
                for(int j=0;j<list.size();j++){
                    Map<String, Object> map = list.get(j);
                    String type = String.valueOf(map.get("DOC_FILE_TYPE"));
                    if("pdf".equalsIgnoreCase(type)){
                        String path = String.valueOf(map.get("PATH"));
                        String doc_mnt = String.valueOf(map.get("DOC_MNT"));
                        Boolean aBoolean = PdfIsEncryption(doc_mnt + path);
                        if(aBoolean){
                            System.out.println(doc_mnt + path+"加密不添加水印");
                            continue;
                        }
                        String real_doc_name = String.valueOf(map.get("REAL_DOC_NAME"));
                        String doc_id = String.valueOf(map.get("DOC_ID"));
                        if(!"".equals(columnStr))
                            maps2 = actArchiveDataMapper.executeSql("select "+columnStr+" from "+fileTableName+" where id = " +
                                    "(select con_table_id from "+tableName+" where doc_id = "+doc_id+")");

                        String imagePath = SealmanageService.getImagePath(Long.valueOf(sealManageId), maps2.size()!=0? JSON.toJSONString(maps2):"null");
                        //image_path = imagePath.getData();
                        //while (imagePath!=null){
                            try {
                                InputStream inputStream = new FileInputStream(new File(doc_mnt+path));
                                //生成归档章图片
                                ByteArrayOutputStream qRcodePngStream = getQRcodePngStream(imagePath);
                                byte[] data = qRcodePngStream.toByteArray();
                                String newPath = config_value + File.separator + tenantCode + File.separator + real_doc_name;
                                PdfUtil.addImage(inputStream,newPath,data,Integer.valueOf(x_position),Integer.valueOf(y_position),Integer.valueOf(total_width),Integer.valueOf(total_height),"0".equals(image_path)?true:false);
                                //有归档章的覆盖无归档章的
                                FileUtils.copyFile(new File(newPath),new File(doc_mnt+path));
                                File file = new File(newPath);
                                if(file.exists()){   //删除临时文件
                                    file.delete();
                                }
                            } catch (FileNotFoundException e) {
                                e.printStackTrace();
                            } catch (DocumentException e) {
                                e.printStackTrace();
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        //}

                    }
                }

            }
        }
    }
    public Boolean PdfIsEncryption(String file){
        PdfReader reader = null;
        try {
            reader = new PdfReader(file);
            return reader.isEncrypted();
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            if(reader !=null){
                reader.close();
            }
        }
        return false;
    }
    public static ByteArrayOutputStream getQRcodePngStream(String path) {
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        FileImageInputStream input = null;
        try {
            input = new FileImageInputStream(new File(path));
            byte[] buf = new byte[1024];
            int numBytesRead = 0;
            while ((numBytesRead = input.read(buf)) != -1) {
                output.write(buf, 0, numBytesRead);
            }
        }catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                output.close();
                if(input!=null) input.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return output;
    }
    @Override
    public void batchUpdateBorrowState(Map<String, Object> borrowData, String state,List<String> archiveNotAgree) {
        String tenantCode = SecurityUtils.getTenantCode().toUpperCase();
        System.out.println(tenantCode);
        String borrowId = String.valueOf(borrowData.get("borrowId"));
        int i = actArchiveDataMapper.updateYqdaBorrowState(borrowId,state);
        if (archiveNotAgree!=null&&archiveNotAgree.size()!=0){
            actArchiveDataMapper.updateYqdaBorrowItemStateWithDaIdAndBorrowId(borrowId,"1",archiveNotAgree);
        }

    }

    @Override
    public String getBusinessIdFromWorkFlowArchiveSaveByInstanceId(String instanceId) {
        return actArchiveDataMapper.getBusinessIdFromWorkFlowArchiveSaveByInstanceId(instanceId,SecurityUtils.getLoginUser().getUser().getTenantCode());
    }

    @Override
    public void batchUpdateArchiveColumn(List<Map<String, Object>> archiveData, String column, String state){
        //return actArchiveDataMapper.updateActArchiveDataByDeployId(processInstanceId);
        String tenantCode = SecurityUtils.getTenantCode().toUpperCase();
        System.out.println(tenantCode);
        StringBuilder sqlBulider = new StringBuilder();
        List<Map<String,Object>> sqlList = new ArrayList<>();
        for (Map<String, Object> archive:archiveData){
            String archiveAgreeStatus = String.valueOf(archive.get("archiveAgreeStatus"));
            String jsType = String.valueOf(archive.get("JS_TYPE"));
            String stateRewrite = state;
            if ("0".equals(jsType)){
                //单行数据不同意
                stateRewrite = "9";
            }else if ("1".equals(jsType)){
                //单行数据不同意
                stateRewrite = "10";
            }
            String daType = String.valueOf(archive.get("DA_TYPE"));
            String daId = String.valueOf(archive.get("ID"));
            String subTableName = String.valueOf(archive.get("SUB_TABLE_NAME"));
            String categoryId = String.valueOf(archive.get("CATEGORY_ID"));
            String mainTableName = "F".equals(daType.toUpperCase())?"YQDA":"V".equals(daType.toUpperCase())?"YQFOLDER":"X".equals(daType.toUpperCase())?"YQITEM":"";
            String mainTableId = "F".equals(daType.toUpperCase())?"DA_ID":"V".equals(daType.toUpperCase())?"FOLDER_ID":"X".equals(daType.toUpperCase())?"ITEM_ID":"";
            Map<String,Object> map = new HashMap<>();
            map.put("mainTableName",tenantCode+"_"+mainTableName);
            map.put("mainTableId",mainTableId);
            map.put("subTableName",subTableName);
            map.put("state",stateRewrite);
            map.put("daId",daId);
            map.put("tenantCode",tenantCode);
            map.put("daType",daType);
            map.put("column",column);
            if ("V".equals(daType)){
                String innerFileTableName = actArchiveDataMapper.getInnerFileTableName(categoryId,tenantCode);
                map.put("innerFileTableName",innerFileTableName);
            }
            if ("X".equals(daType)){
                String innerFolderTableName = actArchiveDataMapper.getInnerFolderTableName(categoryId,tenantCode);
                map.put("innerFolderTableName",innerFolderTableName);
                String innerFileTableName = actArchiveDataMapper.getInnerFileTableName(categoryId,tenantCode);
                map.put("innerFileTableName",innerFileTableName);
            }
            sqlList.add(map);
        }
        actArchiveDataMapper.batchUpdateArchiveColumn(sqlList);
    }

}
